/**
 *
 */
package anyware.common.json;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonBeanProcessor;

import org.apache.commons.lang.Validate;

/**
 * {@link JsonBeanProcessor} for generic JavaBean.
 * 
 * 
 * @author keke<keke@codehaus.org>
 * @revision $Revision: 111 $
 * @version
 */
public class ToStringBeanProcessor implements JsonBeanProcessor {

    /*
     * (non-Javadoc)
     * 
     * @see net.sf.json.processors.JsonBeanProcessor#processBean(java.lang.Object,
     *      net.sf.json.JsonConfig)
     */
    public JSONObject processBean(final Object bean, final JsonConfig arg1) {
        Validate.notNull(bean);
        final JSONObject obj = new JSONObject();
        obj.put("$", bean.toString());
        obj.put("type", bean.getClass().getName());
        return obj;
    }

}
